package com.nexgo.payment.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.nexgo.payment.R;
import com.nexgo.payment.util.NetworkUtils;
import com.nexgo.payment.util.ToastUtils;

/**
 * 监听网络状态，网络状态变化是接收到此广播
 *
 * @author 谭忠扬-YuriTam
 * @date 2016年1月18日
 */
public class NetReceiver extends BroadcastReceiver {
	private static final String TAG = NetReceiver.class.getSimpleName();

	@Override
	public void onReceive(Context context, Intent intent) {
		//全局监听网络状态广播
		if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
			//判断网络是否连接
			if (NetworkUtils.isAvailable(context)){
				ToastUtils.showToast(context.getString(R.string.network_is_connected));
			}else {
				ToastUtils.showToast(context.getString(R.string.network_disconnected));
			}
		}
	}

}
